package com.tanjiaming99.service;

import com.spring.BeanPostProcessor;
import com.spring.Component;

/**
 * @Author tanjiaming99.com
 * @Date 2021/12/14 23:23
 * 初始化前后的操作
 * 这是统一的，不是针对某一个bean的
 **/
@Component("myBeanPostProcessor")
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        System.out.println("初始化前。。。");
        if (beanName.equals("userService")){
            ( (UserService)bean).setName("这个人真是太帅了了了了");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) {
        System.out.println("初始化后。。。");
        return bean;
    }
}
